//
//  YWLocationManager.m
//  maintain
//
//  Created by 郑想 on 16/2/27.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWLocationManager.h"
#import <AMapLocationKit/AMapLocationKit.h>

@interface YWLocationManager ()
@property (nonatomic, strong) AMapLocationManager* locationManager;
@end

@implementation YWLocationManager
YWSingletonM(Manager)

- (void)startMapLocationSever{
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
}

- (void)setUpLocationAccuracy:(CLLocationAccuracy)accuracy{
    [self.locationManager setDesiredAccuracy:accuracy];
}

- (AMapLocationManager*)locationManager{
    if (!_locationManager) {
        AMapLocationManager* locationManager = [[AMapLocationManager alloc] init];
        _locationManager = locationManager;
    }
    return _locationManager;
}

- (void)locationInfoWithCompletionBlock:(YWMapLocatingCompletionBlock)block{
    [self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation* location, AMapLocationReGeocode* regeocode, NSError* error) {
        if (block) {
            block(error ? @"未能定位到具体地址" : regeocode.formattedAddress, error, location);
        }
    }];
}

- (void)cancelLocationServer{
    [self.locationManager stopUpdatingLocation];
}

@end
